package com.timer;

import java.sql.Time;
import java.util.Date;
import java.util.TimerTask;
import java.util.Timer;

public class TimerTest extends TimerTask {
    int count ;
    private String jobName = "";
    Timer timer;

    public TimerTest(String jobName) {
        super();
        this.count =1;
        this.jobName = jobName;
        timer = new Timer();
    }

    @Override
    public void run() {
        if(count>=5){
            System.out.println(String.format("今天晚上:%s,%s次，明天再来",jobName,count));
            timer.cancel();

        }
        System.out.println(String.format("执行任务:%s,开始时间:%s,操了%s次",jobName,new Date(),count));
        count++;


    }


    public static void main(String[] args) {
//
        TimerTest timerTest = new TimerTest("操妹妹");
        timerTest.timer.schedule(timerTest,1000,1000);
        TimerTest timerTest2 = new TimerTest("操哥哥");
        timerTest2.timer.schedule(timerTest2,1000,1000);
    }
}
